package com.itestor.iptv.modules.common.actions;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.itestor.iptv.global.GlobalConstant;
import com.itestor.iptv.modules.common.service.RegionManageService;
import com.itestor.iptv.modules.common.utils.CommonConstant;
import com.itestor.iptv.modules.common.vo.RegionManageOBJ;
import com.itestor.iptv.global.exception.WebApplicationException;
import com.itestor.iptv.global.utils.LoggerUtils;


/**
 * 
 * @author Mr.li
 *
 */
public class RegionManageModifyAction extends Action {

	/**
	 * Logger for this class.
	 */
	private static final Logger logger = Logger.getLogger(UserAddAction.class);
	
	/**
	 * 
	 */
    private RegionManageService regionManageService;

	/**
	 * @param mapping struts mapping
	 * @param request request
	 * @param form action form
	 * @param response response
	 * @return action forward
	 * @throws Exception any exception
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		String regionName = request.getParameter("regionName");
		
		if (StringUtils.isEmpty(regionName)) {
			throw new WebApplicationException("global.error.submit", GlobalConstant.PROPERTIES_BUNDLE);
		}
		
		RegionManageOBJ region = regionManageService.get(regionName);
		
		if (region != null) {			
			String prentRegionId = request.getParameter("prentRegionId");			
			region.setPrentRegionId(Integer.parseInt(prentRegionId));
			
			request.setAttribute(CommonConstant.REQUEST_ATTR_REGION, region);
			
			LoggerUtils.logActionInfo("Modify the RegionManage - regionName: " + regionName, logger, request);

			regionManageService.modify(region);
		}
		
		return mapping.findForward(GlobalConstant.FORWARD_SUCCESS);
	}

    public void setRegionManageService(RegionManageService pRegionManageService) {
        regionManageService = pRegionManageService;
    }
	
	
}
